<test>
    <settings>
      <allow_suspicious_low_cardinality_types>1</allow_suspicious_low_cardinality_types>
    </settings>

    <query>WITH toUInt8(number) AS k, toUInt64(k) AS k1, k AS k2 SELECT k1, k2, count() FROM numbers(100000000) GROUP BY k1, k2</query>
    <query>WITH toUInt8(number) AS k, toUInt16(k) AS k1, toUInt32(k) AS k2, k AS k3 SELECT k1, k2, k3, count() FROM numbers(100000000) GROUP BY k1, k2, k3</query>
    <query>WITH toUInt8(number) AS k, k AS k1, k + 1 AS k2 SELECT k1, k2, count() FROM numbers(100000000) GROUP BY k1, k2</query>
    <query>WITH toUInt8(number) AS k, k AS k1, k + 1 AS k2, k + 2 AS k3, k + 3 AS k4 SELECT k1, k2, k3, k4, count() FROM numbers(100000000) GROUP BY k1, k2, k3, k4</query>
    <query>WITH toUInt8(number) AS k, toUInt64(k) AS k1, k1 + 1 AS k2 SELECT k1, k2, count() FROM numbers(100000000) GROUP BY k1, k2</query>

    <create_query>create table group_by_fk(a UInt32, b UInt32, c LowCardinality(UInt32), d Nullable(UInt32), e UInt64, f UInt64, g UInt64, h LowCardinality(UInt64), i Nullable(UInt64)) engine=MergeTree order by tuple()</create_query>

    <fill_query>insert into group_by_fk select number, number, number % 10000, number % 2 == 0 ? number : Null, number, number, number, number % 10000, number % 2 == 0 ? number : Null from numbers_mt(1e7) settings max_insert_threads=8</fill_query>

    <!-- keys64_two_level -->
    <query>select a, b from group_by_fk group by a, b format Null</query>
    <!-- low_cardinality_keys128_two_level -->
    <query>select a, c from group_by_fk group by a, c format Null</query>
    <!-- nullable_keys128_two_level -->
    <query>select a, d from group_by_fk group by a, d format Null</query>

    <!-- keys128_two_level -->
    <query>select e, f from group_by_fk group by e, f format Null</query>
    <!-- low_cardinality_keys128_two_level -->
    <query>select e, h from group_by_fk group by e, h format Null</query>
    <!-- nullable_keys256_two_level -->
    <query>select e, i from group_by_fk group by e, i format Null</query>

    <!-- keys256_two_level -->
    <query>select e, f, g from group_by_fk group by e, f, g format Null</query>
    <!-- low_cardinality_keys256_two_level -->
    <query>select e, f, h from group_by_fk group by e, f, h format Null</query>
    <!-- nullable_keys256_two_level -->
    <query>select e, f, i from group_by_fk group by e, f, i format Null</query>

    <drop_query>drop table group_by_fk</drop_query>
</test>
